package com.eattravel.service.impl;
/*
    wy 商品收藏service接口实现
    描述：商品收藏service接口实现
    最后修改时间：9.19/16.43
*/
import com.eattravel.dto.PageInfoResult;
import com.eattravel.mapper.CommodityCollectionMapper;
import com.eattravel.mapper.StoreCollectionMapper;
import com.eattravel.pojo.Commodity;
import com.eattravel.pojo.Store;
import com.eattravel.service.CommodityColletionService;
import com.eattravel.service.StoreColletionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StoreColletionServiceImpl implements StoreColletionService {

    @Autowired
    StoreCollectionMapper storeCollectionMapper;

    @Override
    public PageInfoResult<Store> selectAllStoreCollection(PageInfoResult pageParameter,String userId) {
        //根据传来的分页信息查询数据
        PageHelper.startPage(pageParameter.getCurrPage(), pageParameter.getPageSize());
        List<Store> stores =storeCollectionMapper.selectAllStoreCollection(userId);
        //将查询的数据装入到pageinfo
        PageInfo<Store> pageInfo = new PageInfo<Store>(stores);
        // 查询的当前页数据信息
        List<Store> empList = pageInfo.getList();
        // 获取查询的总条数
        pageParameter.setTotalSize(pageInfo.getTotal());
        pageParameter.setDataList(empList);
        return pageParameter;
    }

    @Override
    public int cancleStoreCollection(String userId, String storeId) {
        int rs=storeCollectionMapper.cancleStoreCollection(userId,storeId);
        return rs;
    }

    @Override
    public int addToColl(String userId, String commodityId) {
        //先查一下收藏中是否存在这个商家
        int rs = storeCollectionMapper.selectSimpleCollShop(userId,commodityId);
        if (rs > 0) {
            //如果收藏中已经有了这个商家就返回1
            return 1;
        }
        //如果收藏中没有了这个商家就插入这个   返回0
        int rs1 = storeCollectionMapper.addToColl(userId,commodityId);
        System.out.println(rs1);
        return 0;
    }
}
